package com.ye.system.user.controller;

import com.ye.common.utils.R;
import com.ye.system.user.dto.SysUserDto;
import com.ye.system.user.entity.SysUser;
import com.ye.system.user.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: baby
 * @Date: 2023/10/9 23:28
 * @Description:
 */
@Api(value = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private SysUserService userService;


    @ApiOperation("创建用户")
    @PostMapping("/create")
    public R create(@RequestBody SysUserDto sysUserDto){
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(sysUserDto,sysUser);
        return R.ok(userService.save(sysUser));
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        return R.ok(userService.removeById(id));
    }

}
